﻿@{
    ViewBag.Title = "房源搜索";
    Layout = "~/Views/Shared/_SearchLayout.cshtml";
}
@model PagedList<HouseAgencySite.Models.HouseInfos>
@{
    List<SelectListItem> listHuXing = HouseAgencySite.Utils.ParamHelper.HuXing(true, "");
    List<SelectListItem> listHouseType = HouseAgencySite.Utils.ParamHelper.HouseType(true, "");
}

<div class="row">
    <div class="col-md-12 text-center">


        <div class="tabbable" id="searchType">
            <ul class="nav nav-tabs">
                <li class="@(Request["id"]=="0"?"active":"")"><a href="#all" data-toggle="tab" contenteditable="false">全部</a></li>
                <li class="@(Request["id"]=="1"?"active":"")"><a href="#all" data-toggle="tab" contenteditable="false">出租</a></li>
                <li class="@(Request["id"]=="2"?"active":"")"><a href="#all" data-toggle="tab" contenteditable="false">出售</a></li>
                <li class="@(Request["id"]=="3"?"active":"")"><a href="#all" data-toggle="tab" contenteditable="false">写字楼</a></li>
                <li class="@(Request["id"]=="4"?"active":"")"><a href="#all" data-toggle="tab" contenteditable="false">底商</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="all" contenteditable="false">
                    <p>
                        <form class="navbar-form navbar-left" role="search" action="@Url.Action("Search")" method="post">
                            @Html.Hidden("id", Request["id"])
                            @Html.Hidden("PageIndex", Request["pageIndex"])
                            <div class="form-group">
                                <a href="/">
                                    <img src="~/Content/images/logo.png" width="50" height="50" /></a><input type="text" id="keywords" name="keywords" class="form-control" placeholder="Search" value="@Request["keywords"]" style="width: 700px;" size="500">
                            </div>
                            <button type="submit" class="btn btn-primary">搜  索</button>
                        </form>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
<hr style="border: 3px solid #ccc;" />
<div class="row">
    <div class="col-md-12">
        @if (Model.Count > 0)
        {
            foreach (var item in Model)
            {
            <div class="row">
                <div class="col-md-12">
                    <dl>
                        <dt><span style="margin-left: 20px; color: red;">[@listHouseType.FirstOrDefault(o => o.Value == item.HouseType.ToString()).Text]</span>&nbsp;&nbsp;<a href="@Url.Action("Detail", new { id = item.Guid })" title="@item.Title"  style="font-size:16px;"><strong>@item.Title</strong></a>
                            <span style="margin-left: 20px; color: red;">@listHuXing.FirstOrDefault(o => o.Value == item.HuXing.ToString()).Text</span>
                            <span style="margin-left: 20px; color: red;">@item.Price.ToString("C")</span>
                            <span style="margin-left: 60px;" class="address">@item.AddressDetail</span></dt>
                        <dd>
                           @Html.Raw(item.ZhaiYao)</dd>
                        <dd>
                            @if (item.Files != null && item.Files.Count > 0)
                            {
                                foreach (var img in item.Files)
                                {
                                    if (img != null && !string.IsNullOrEmpty(img.Url))
                                    {
                                <a href="/images/@(img.Url)" rel="prettyPhoto" title="@item.Title">
                                    <img src="/images/_thumbs/@(img.Url)"  class="img-rounded" width="80" height="80" alt="@item.Title"/></a>
                                    }else
                                    {
                                      <a href="/images/@(img.Url)" rel="prettyPhoto" title="@item.Title">
                                    <img src="/content/images/noimg.jpg"  class="img-rounded" width="80" height="80" alt="@item.Title"/></a>
                                    }
                                }
                            }
                        </dd>
                    </dl>
                </div>
            </div>
            }
            <div class="text-left">
                <ul class="pagination " TotalPage="@Model.TotalPageCount">

                    <li id="first" style="@(Model.CurrentPageIndex == 1 ? "display:none;" : "")"><a href="javascript:void(0);">首页</a></li>
                    <li id="prev" style="@(Model.CurrentPageIndex == 1 ? "display:none;" : "")"><a href="javascript:void(0);">上一页</a></li>
                    @for (int i = 1; i <= Model.TotalPageCount; i++)
                    {       
                        <li class="pageitem @(i == Model.CurrentPageIndex ? "active" : "")"><a href="javascript:void(0);">@(i)</a></li>
                    }
                    <li id="next"  style="@(Model.CurrentPageIndex == Model.TotalPageCount ? "display:none;" : "")"><a href="javascript:void(0);">下一页</a></li>
                    <li id="last"  style="@(Model.CurrentPageIndex == Model.TotalPageCount ? "display:none;" : "")"><a href="javascript:void(0);">末页</a></li>
                    <li><a>共<strong style="color: red;">@(Model.TotalItemCount)</strong>条记录</a></li>
                </ul>
            </div>


        }
        else
        { 
            <div class="alert alert-danger text-center">暂无满足条件的信息！</div>
        }
    </div>
</div>
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.prettyphoto.js"></script>
<link href="~/Content/css/prettyphoto.css" rel="stylesheet" media="screen" charset="utf-8" />
<script src="~/Scripts/Pager.js"></script>
<script>

    function highlight(key) {
        var key = key.split(' ');
        for (var i = 0; i < key.length; i++) {
            var rng = document.body.createTextRange();
            if (typeof (key[i]) != "undefined" && key[i].length > 0) {
                while (rng.findText(key[i]))
                    rng.pasteHTML('<span style="color:#F00;font-weight:bold;">' + rng.text + '</span>');
            }
        }
    }
    $(function () {
        $("a[rel^='prettyPhoto']").prettyPhoto();
        var keywords = $.trim($("#keywords").val());
        highlight(keywords);
        $("li", "#searchType").click(function () { $("#id").val($(this).index()); });
        $("li", ".pagination").click(function () { $("#PageIndex").val($.trim($(".active", ".pagination").find("a").html())); $("form").submit() });
    });
</script>
